
This resource address adds a SQL View to the specified schema on the specified database.
| URL Parameters | |
|---|---|
| format | The format of the posted data. Can be either
html, json, or xml (default). This value overrides
the Accept header if both are present. |
Upon success, MarkLogic Server returns status code 201 (Created). If the schema already exists or if the payload is malformed, a status code of 400 (Bad Request) is returned. A status code of 401 (Unauthorized) is returned if the user does not have the necessary privileges.
manage-admin role, or the following
privilege: http://marklogic.com/xdmp/privileges/manage-admin
The view-name property is required and
will be converted to all lowercase. The schema-name property must be selected
from the list of view-schemas. By default, view-schema-name is set to
main. The scope property can be either none
(default), {"collection":""}, or {"namespace-uri":"",
"localname":""}. The columns properties must reference existing
indexes on the database.
Note: The properties described here are for XML payloads. In general they are the same for
JSON, with the exception that, in JSON, columns, views, and
permissions are expressed in singular form. For example, in JSON,
permissions is instead permission and the format is:
"permission":[{"role-name":"name", "capability":"cap"}].
The following is the payload expected to create a column for each type of range index.
Path Range Index:
"path-reference":{
"path-expression":"path",
"scalar-type":"type",
"collation":"http://marklogic.com/collation/codepoint"
}
Element Range Index (The collation element is optional):
"element-reference":{
"namespace-uri":"",
"localname":"name",
"scalar-type":"type",
"collation":"http://marklogic.com/collation/"
}
Attribute Range Index (The collation element is optional):
"element-attribute-reference":{
"parent-namespace-uri":"",
"parent-localname":"name",
"namespace-uri":"",
"localname":"name",
"scalar-type":"type",
"collation":"http://marklogic.com/collation/"
}
Field Index:
"field": [{
"field-name": "name",
}]
For details on schemas and views, see SQL on MarkLogic Server in the SQL Data Modeling Guide.
view-nameschema-nameelement-scopeThis is a complex structure with the following children:
namespace-urilocalnamecollection-scopeThis is a complex structure with the following children:
collectionorderedcolumnsThis is a complex structure with the following children:
columnThis is a complex structure with the following children:
column-namects:base-referencefieldsThis is a complex structure with the following children:
fieldThis is a complex structure with the following children:
field-namepermissionsThis is a complex structure with the following children:
permissionThis is a complex structure with the following children:
role-namecapability
cat myTable1.json
==>
{
"view-name": "myTable1",
"element-scope":{"namespace-uri":"", "localname":"message"},
"column": [
{
"column-name": "message_list",
"element-attribute-reference": {
"parent-namespace-uri" : "",
"parent-localname": "message",
"namespace-uri":"",
"localname": "list",
"scalar-type":"string"
}
},
{
"column-name": "subject",
"element-reference": {
"namespace-uri": "",
"localname": "subject",
"scalar-type": "string"
}
},
{
"column-name": "body_url",
"path-reference": {
"path-expression": "/message/body/url",
"scalar-type": "anyURI",
"collation":"http://marklogic.com/collation/codepoint"
}
}],
"field": [
{"field-name": "position"}
]
}
curl -X POST --anyauth --user $MANAGEADMIN:$MANAGEPASS \
--header "Content-Type:application/json" -d @myTable1.json \
http://localhost:8002/manage/v2/databases/SQLschemas/view-schemas/main/views?format=json
==> Creates a SQL view, named "myTable1", in the 'main' schema
in the SQLschemas database.